<?php
/*
* @Author: hzwlxy
* @Email: 120235331@qq.com
* @Github: http：//www.github.com/siaoynli
* @Date: 2019/6/28 10:15
* @Version:
* @Description:
*/
namespace Modules\Web\Http\Controllers;


use App\Models\Admin;
use App\Models\Token;
use Carbon\Carbon;

class TokenController extends BaseController
{

    public  function confirmEmailToken($token){
        $token = Token::where("token", $token)->where("action","register")->first();
        if(!$token) abort(404);

        switch ($token->table_name) {
            case "admins":
                $admin = Admin::where("email", $token->name)->where("email_verified_at", null)->first();
                 if($admin) {
                      $admin->email_verified_at=Carbon::now();
                      $admin->save();
                     $token->delete();
                     dd("账户激活");
                 }
                 $token->delete();
                 dd("账户已经激活");

                break;
            default:
                break;
        }
    }

}
